package com.itlv.recursion.common.util;

import com.itlv.recursion.common.result.BusinessException;
import com.itlv.recursion.common.result.ResultEnum;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

import java.util.Collection;

/**
 * 断言工具类
 *
 * @author Lv
 * @date 2022/7/14
 */
public class AssertUtil extends Assert {
    /**
     * 断言对象非空
     *
     * @param object     判断对象
     * @param resultEnum 通用返回值枚举类
     */
    public static void notNull(@Nullable Object object, ResultEnum resultEnum) {
        if (PubUtils.isNull(object)) {
            throw new BusinessException(resultEnum);
        }
    }

    /**
     * 断言集合非空
     *
     * @param collection 判断集合
     * @param resultEnum 通用返回值枚举类
     */
    public static void notEmpty(@Nullable Collection<?> collection, ResultEnum resultEnum) {
        if (PubUtils.isEmpty(collection)) {
            throw new BusinessException(resultEnum);
        }
    }

    /**
     * 断言字符串非空
     *
     * @param string     判断字符串
     * @param resultEnum 通用返回值枚举类
     */
    public static void notEmpty(@Nullable String string, ResultEnum resultEnum) {
        if (PubUtils.isEmpty(string)) {
            throw new BusinessException(resultEnum);
        }
    }
}
